Use precise if it's there
authorAlex Crichton <alex@alexcrichton.com>
Thu, 31 Jul 2014 17:20:33 +0000 (10:20 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 31 Jul 2014 17:51:32 +0000 (10:51 -0700)
src/cargo/core/resolver.rs
src/cargo/sources/git/source.rs
src/cargo/sources/git/utils.rs

index 579ae7f7e06e1589747604532f8cd7f5fc3c467d..cb97b83d3b4d8ae3d9e58ab0775d36fd29e376ff 100644 (file)
@@ -104,7 +104,8 @@ impl<E, D: Decoder<E>> Decodable<D, E> for EncodablePackageId {
     fn decode(d: &mut D) -> Result<EncodablePackageId, E> {
         let string: String = raw_try!(Decodable::decode(d));
         let regex = regex!(r"^([^ ]+) ([^ ]+)(?: \(([^\)]+)\))?$");
-        let captures = regex.captures(string.as_slice()).expect("invalid serialized PackageId");
+        let captures = regex.captures(string.as_slice())
+                            .expect("invalid serialized PackageId");
 
         let name = captures.at(1);
         let version = captures.at(2);
index 5f0c1e3ddf683913901421639409a118519f2544..61759e65eef321b458f9928c7183a91775515614 100644 (file)
@@ -23,7 +23,8 @@ pub struct GitSource<'a, 'b> {
 }
 
 impl<'a, 'b> GitSource<'a, 'b> {
-    pub fn new<'a, 'b>(source_id: &SourceId, config: &'a mut Config<'b>) -> GitSource<'a, 'b> {
+    pub fn new<'a, 'b>(source_id: &SourceId,
+                       config: &'a mut Config<'b>) -> GitSource<'a, 'b> {
         assert!(source_id.is_git(), "id is not git, id={}", source_id);
 
         let reference = match source_id.kind {
@@ -40,6 +41,11 @@ impl<'a, 'b> GitSource<'a, 'b> {
         let checkout_path = config.git_checkout_path()
             .join(ident.as_slice()).join(reference.as_slice());
 
+        let reference = match source_id.precise {
+            Some(ref s) => s,
+            None => reference,
+        };
+
         GitSource {
             remote: remote,
             reference: GitReference::for_str(reference.as_slice()),
@@ -163,7 +169,8 @@ impl<'a, 'b> Source for GitSource<'a, 'b> {
             self.remote.db_at(&self.db_path)
         };
 
-        let checkout = try!(repo.copy_to(self.reference.as_slice(), &self.checkout_path));
+        let checkout = try!(repo.copy_to(self.reference.as_slice(),
+                                         &self.checkout_path));
 
         let source_id = self.source_id.with_precise(checkout.get_rev().to_string());
         let path_source = PathSource::new(&self.checkout_path, &source_id);
index 3f15e8462c0411756cf426b4ed0c9ccdfaa2f9a9..3a3a0a583e9e19fb15ff7b19e3bfb4de27f7b2be 100644 (file)
@@ -182,7 +182,10 @@ impl GitDatabase {
         let checkout = try!(GitCheckout::clone_into(dest, self.clone(),
                                   GitReference::for_str(reference.as_slice())));
 
-        try!(checkout.fetch());
+        if self.remote.has_ref(dest, reference.as_slice()).is_err() {
+            try!(checkout.fetch());
+        }
+        try!(checkout.reset(reference.as_slice()));
         try!(checkout.update_submodules());
 
         Ok(checkout)
@@ -264,7 +267,6 @@ impl GitCheckout {
         // In this case we just use `origin` here instead of the database path.
         git!(self.location, "fetch", "--force", "--quiet", "origin");
         git!(self.location, "fetch", "--force", "--quiet", "--tags", "origin");
-        try!(self.reset(self.revision.as_slice()));
         Ok(())
     }